using System;
using System.Collections.Generic;
using System.Text;
using CMS.BIZ;
using AAM.DAL;
using AAM.BIZ;
using AAM.SQL;

namespace CMS.BOP
{
    public class SqlBizMessageGroupProvider : SqlBizObjectProvider<BizMessageGroup>
    {
        public BizMessageGroup Read(int groupId)
        {
            return Read(new ObjectID(BizMessageGroup.ObjectType,new object[]{groupId}));
        }
        public bool Delete(int groupId)
        {
            return Delete(new ObjectID(BizMessageGroup.ObjectType, new object[] { groupId }));
        }
        public bool Delete(int groupId, int memberId)
        {
            Command command = Connection.CreateCommand("DELETE FROM MessageGroups WHERE MessageGroupID=? AND MemberID=?");
            command.AddParameter(groupId);
            command.AddParameter(memberId);
            int result = command.ExecuteNonQuery();
            command.Dispose();
            return result > 0;
        }
        public BizMessageGroup ReadByMemberID(int groupId,int memberId)
        {
            Command command = Connection.CreateCommand("SELECT * FROM MessageGroups WHERE MessageGroupID=? AND MemberID=?");
            command.AddParameter(groupId);
            command.AddParameter(memberId);
            return CreateFromCommand(command);
        }
        public List<BizMessageGroup> ReadByMemberID(int memberId)
        {
            Command command = Connection.CreateCommand("SELECT * FROM MessageGroups WHERE MemberID=?");
            command.AddParameter(memberId);
            return CreateListFromCommand(command);
        }
    }
}
